<template>
  <p-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel">
    <p-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <p-form :form="form">
        <p-row>

		  <p-col  :span="24">
			<p-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'type', validatorRules.type]" placeholder="请输入状态" style="width: 100%"/>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="线体内码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'lineid', validatorRules.lineid]" placeholder="请输入线体内码"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="线体编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['lineno', validatorRules.lineno]"
						:trigger-change="true"
						org-fields="lineid,lineno,linename"
						dest-fields="lineid,lineno,linename"
						code="line_select"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="线体名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'linename', validatorRules.linename]" placeholder="请输入线体名称"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="地址码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'addressCode', validatorRules.addressCode]" placeholder="请输入地址码"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="工序工单编号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'mobillno', validatorRules.mobillno]" placeholder="请输入工序工单编号"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="工序工单数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moQty', validatorRules.moQty]" placeholder="请输入工序工单数量"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="PN/SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'pnsn', validatorRules.pnsn]" placeholder="请输入PN/SN"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="组件编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moduleno', validatorRules.moduleno]" placeholder="请输入组件编码"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="组件名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'moduleidname', validatorRules.moduleidname]" placeholder="请输入组件名称"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="不良标识" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   v-decorator="[ 'badMark', validatorRules.badMark]" placeholder="请输入不良标识" style="width: 100%"/>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="箱号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'caseNumber', validatorRules.caseNumber]" placeholder="请输入箱号"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="栈板" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'pallet', validatorRules.pallet]" placeholder="请输入栈板"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="下一工站" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'belowStation', validatorRules.belowStation]" placeholder="请输入下一工站"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="返工" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input  v-decorator="[ 'rework', validatorRules.rework]" placeholder="请输入返工"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="工站编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['workstationcode', validatorRules.workstationcode]"
						:trigger-change="true"
						org-fields="wpno,wpname"
						dest-fields="workstationcode,workstationname"
						code="mes_q_ba_station"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="工站名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'workstationname', validatorRules.workstationname]" placeholder="请输入工站名称"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="物料编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<f-popup
						contextPath="basic-business"
						v-decorator="['mcode', validatorRules.mcode]"
						:trigger-change="true"
						org-fields="id,mcode,mname,sprc,mexplain"
						dest-fields="mid,mcode,mname,sprc,mexplain"
						code="wms_cpinfo"
						@callback="popupCallback"/>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mname', validatorRules.mname]" placeholder="请输入物料名称"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="物料规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'sprc', validatorRules.sprc]" placeholder="请输入物料规格型号"></p-input>
			</p-form-item>
		  </p-col>

		  <p-col  :span="24">
			<p-form-item label="物料描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readOnly v-decorator="[ 'mexplain', validatorRules.mexplain]" placeholder="请输入物料描述"></p-input>
			</p-form-item>
		  </p-col>


        </p-row>
      </p-form>

      <!-- 子表单区域 -->
      <p-tabs v-model="activeKey" @change="handleChangeTabs">
        <p-tab-pane tab="工序条码采集历史记录" :key="refKeys[0]" :forceRender="true">
          <j-editable-table
            :ref="refKeys[0]"
            :loading="mesMfContainerBindingLogTable.loading"
            :columns="mesMfContainerBindingLogTable.columns"
            :dataSource="mesMfContainerBindingLogTable.dataSource"
            :maxHeight="300"
            :rowNumber="true"
            :rowSelection="true"
            :actionButton="true"/>
        </p-tab-pane>
      </p-tabs>
    </p-spin>
  </p-modal>
</template>

<script>

  import pick from 'lodash.pick'
  import { FormTypes,getRefPromise } from '@/utils/JEditableTableUtil'
  import { JEditableTableMixin } from '@/mixins/JEditableTableMixin'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'MesMfContainerBindingListModal',
    mixins: [JEditableTableMixin],
    components: {
    },
    data() {
      return {
        labelCol: {
          span: 6
        },
        wrapperCol: {
          span: 16
        },
        labelCol2: {
          span: 3
        },
        wrapperCol2: {
          span: 20
        },
        // 新增时子表默认添加几行空数据
        addDefaultRowNum: 1,
        validatorRules: {
          type: {rules: [
          ]},
          lineid: {rules: [
          ]},
          lineno: {rules: [
            {required: true, message: '请输入线体编码!'},
          ]},
          linename: {rules: [
          ]},
          addressCode: {rules: [
            {required: true, message: '请输入地址码!'},
          ]},
          mobillno: {rules: [
            {required: true, message: '请输入工序工单编号!'},
          ]},
          moQty: {rules: [
          ]},
          pnsn: {rules: [
            {required: true, message: '请输入PN/SN!'},
          ]},
          moduleno: {rules: [
          ]},
          moduleidname: {rules: [
          ]},
          badMark: {rules: [
          ]},
          caseNumber: {rules: [
          ]},
          pallet: {rules: [
          ]},
          belowStation: {rules: [
          ]},
          rework: {rules: [
          ]},
          workstationcode: {rules: [
            {required: true, message: '请输入工站编码!'},
          ]},
          workstationname: {rules: [
          ]},
          mcode: {rules: [
            {required: true, message: '请输入物料编码!'},
          ]},
          mname: {rules: [
            {required: true, message: '请输入物料名称!'},
          ]},
          sprc: {rules: [
          ]},
          mexplain: {rules: [
          ]},
        },
        refKeys: ['mesMfContainerBindingLog', ],
        tableKeys:['mesMfContainerBindingLog', ],
        activeKey: 'mesMfContainerBindingLog',
        // 工序条码采集历史记录
        mesMfContainerBindingLogTable: {
          loading: false,
          dataSource: [],
          columns: [
            {
              title: '状态',
              key: 'type',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '线体编码',
              key: 'lineno',
              type: FormTypes.popup,
              contextPath: 'basic-business',
              popupCode: 'line_select',
              destFields: 'lineid,lineno,linename',
              orgFieldse: 'lineid,lineno,linename',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '线体名称',
              key: 'linename',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '地址码',
              key: 'addressCode',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '工序工单编号',
              key: 'mobillno',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '工序工单数量',
              key: 'moQty',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: 'PN/SN',
              key: 'pnsn',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '组件编码',
              key: 'moduleno',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '组件名称',
              key: 'moduleidname',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '不良标识',
              key: 'badMark',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '箱号',
              key: 'caseNumber',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '栈板码',
              key: 'pallet',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '下一工站',
              key: 'belowStation',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '返工',
              key: 'rework',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '工站编码',
              key: 'workstationcode',
              type: FormTypes.popup,
              contextPath: 'basic-business',
              popupCode: 'mes_q_ba_station',
              destFields: 'workstationcode,workstationname',
              orgFieldse: 'wpno,wpname',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '工站名称',
              key: 'workstationname',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '物料编码',
              key: 'mcode',
              type: FormTypes.popup,
              contextPath: 'basic-business',
              popupCode: 'wms_cpinfo',
              destFields: 'mid,mcode,mname,sprc,mexplain',
              orgFieldse: 'id,mcode,mname,sprc,mexplain',
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '物料名称',
              key: 'mname',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
              validateRules: [{ required: true, message: '${title}不能为空' }],
            },
            {
              title: '物料规格型号',
              key: 'sprc',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: '物料描述',
              key: 'mexplain',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },
            {
              title: 'id外键 ',
              key: 'mesMfContainerBindingListId',
              type: FormTypes.input,
              width: '200px',
              placeholder: '请输入${title}',
              defaultValue: '',
            },

            {
              title: 'lineid',
              key: 'lineid',
              type: 'hidden'
            },





            {
              title: 'mid',
              key: 'mid',
              type: 'hidden'
            },




          ]
        },
        url: {
          add: '/mes-manufacture/auto/mesMfContainerBindingList/add',
          edit: '/mes-manufacture/auto/mesMfContainerBindingList/edit',
          mesMfContainerBindingLog: {
            list: '/mes-manufacture/auto/mesMfContainerBindingList/queryMesMfContainerBindingLogByMainId'
          },
        }
      }
    },
    methods: {
      getAllTable() {
        let values = this.tableKeys.map(key => getRefPromise(this, key))
        return Promise.all(values)
      },
      /** 调用完edit()方法之后会自动调用此方法 */
      editAfter() {
        let fieldval = pick(this.model,'type','lineid','lineno','linename','addressCode','mobillno','moQty','pnsn','moduleno','moduleidname','badMark','caseNumber','pallet','belowStation','rework','workstationcode','workstationname','mcode','mname','sprc','mexplain','createBy','createTime','updateBy','updateTime','remark')
        this.$nextTick(() => {
          this.form.setFieldsValue(fieldval)
        })
        // 加载子表数据
        if (this.model.id) {
          let params = { id: this.model.id }
          this.requestSubTableData(this.url.mesMfContainerBindingLog.list, params, this.mesMfContainerBindingLogTable)
        }
      },
      /** 整理成formData */
      classifyIntoFormData(allValues) {
        let main = Object.assign(this.model, allValues.formValue)

        return {
          ...main, // 展开
          mesMfContainerBindingLogList: allValues.tablesValue[0].values,
        }
      },
      validateError(msg){
        this.$message.error(msg)
      },
     popupCallback(row){
       this.form.setFieldsValue(pick(row,'type','lineid','lineno','linename','addressCode','mobillno','moQty','pnsn','moduleno','moduleidname','badMark','caseNumber','pallet','belowStation','rework','workstationcode','workstationname','mcode','mname','sprc','mexplain','createBy','createTime','updateBy','updateTime','remark'))
     },

    }
  }
</script>

<style scoped>
</style>
